<div class="layuimini-main">

    <div class="layui-form layuimini-form">
        <input type="hidden" name="type" id="type">
        <input type="hidden" name="parentId" id="parentId">
        <div class="layui-form-item">
            <label class="layui-form-label required">名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="number" name="sort" placeholder="请输入排序号" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" checked="" name="status" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form','axios', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;
        var axios = layui.axios;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var data=data.field;
            if(data.status=='on'){
                data.status=1;
            }else{
                data.status=0;
            }
           axios.post('dept/add',data).then(function(response){
               debugger
               if(response.data.code==200){
                   layer.msg(response.data.msg);
                   //重新加载表格
                   window.reload()
               }
               //关闭弹出页面
               layer.close(parentIndex);
           }).catch(err=> {
                   console.log(err);
               }
           );

            return false;
        });

    });
</script>